﻿/******************************************************************************
* Author: 671643387@qq.com
* @MR.Luo
*****************************************************************************/

#pragma once

class EchoServer
{
public:
    EchoServer(dev::net::EventLoop& loop);
    ~EchoServer();

	bool open(const char* addr, int port, int backlog)
	{
        return server_.open(addr, port, backlog);
	}

    void close();

    dev::net::TcpServer& getServer(){ return server_; }

private:
    void onConnectionEstablished(dev::net::TcpConnectionPtr& conn);
    void onMessage(dev::net::TcpConnection& conn, dev::net::TcpConnectionInputStream& is);
    void onConnectionError(dev::net::TcpConnection& conn);
    void onConnectionClosing(dev::net::TcpConnection& conn);
    void onConnectionHeartBeat(dev::net::TcpConnection& conn);
    void onConnectionWritable(dev::net::TcpConnection& conn);
private:
    void onServerShutdown(void);
    void dumpStatics(void);

private:
    dev::net::TcpServer server_;
    dev::net::EventLoop& loop_;
};

